﻿using System;
using System.Data;

namespace Common
{
    [Serializable]
    public class unit_logData
    {

        public const string LOG_IDField = "@log_id";

        public const string PRIMARYKEY_Field = @"log_id";

        public const string UNIT_NUMBERField = "@unit_number";

        public const string UNIT_SHELF_NUMBERField = "@unit_shelf_number";

        public const string QUERY_USER_IDField = "@query_user_id";

        public const string QUERY_TIMEField = "@query_time";

        public const string RESULT_FLAGField = "@result_flag";

        private Int32 _log_id;

        private String _unit_number;

        private String _unit_shelf_number;

        private Int32 _query_user_id;

        private DateTime _query_time;

        private Boolean _result_flag;

        public Int32 log_id
        {
            get { return _log_id; }
            set { _log_id = value; }
        }
        public String unit_number
        {
            get { return _unit_number; }
            set { _unit_number = value; }
        }
        public String unit_shelf_number
        {
            get { return _unit_shelf_number; }
            set { _unit_shelf_number = value; }
        }
        public Int32 query_user_id
        {
            get { return _query_user_id; }
            set { _query_user_id = value; }
        }
        public DateTime query_time
        {
            get { return _query_time; }
            set { _query_time = value; }
        }
        public Boolean result_flag
        {
            get { return _result_flag; }
            set { _result_flag = value; }
        }
        public unit_logData()
        {
            _log_id = 0;
            _unit_number = "";
            _unit_shelf_number = "";
            _query_user_id = 0;
            _query_time = DateTime.Now;
            _result_flag = false;
        }
    }

    public class unit_logDataFactory
    {
        public static unit_logData Construct(IDataReader reader)
        {
            unit_logData data = new unit_logData();

            try { data.log_id = Convert.ToInt32(reader["log_id"]); }
            catch { }

            try { data.unit_number = Convert.ToString(reader["unit_number"]); }
            catch { }

            try { data.unit_shelf_number = Convert.ToString(reader["unit_shelf_number"]); }
            catch { }

            try { data.query_user_id = Convert.ToInt32(reader["query_user_id"]); }
            catch { }

            try { data.query_time = Convert.ToDateTime(reader["query_time"]); }
            catch { }

            try { data.result_flag = Convert.ToBoolean(reader["result_flag"]); }
            catch { }

            return data;
        }
        public static Int32 GetPrimaryKey(DataTable dt)
        {
            return GetPrimaryKey(dt, 0);
        }
        public static Int32 GetPrimaryKey(DataTable dt, int rowIndex)
        {
            Int32 PrimaryKey = 0;

            if (dt.Rows.Count < rowIndex + 1)

                return 0;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return 0;

            try { PrimaryKey = Convert.ToInt32(dr[unit_logData.PRIMARYKEY_Field]); }
            catch { }

            return PrimaryKey;
        }
        public static unit_logData Construct(DataTable dt)
        {
            return Construct(dt, 0);
        }
        public static unit_logData Construct(DataTable dt, int rowIndex)
        {
            unit_logData data = new unit_logData();

            if (dt.Rows.Count < rowIndex + 1)

                return null;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return null;

            try { data.log_id = Convert.ToInt32(dr["log_id"]); }
            catch { }

            try { data.unit_number = Convert.ToString(dr["unit_number"]); }
            catch { }

            try { data.unit_shelf_number = Convert.ToString(dr["unit_shelf_number"]); }
            catch { }

            try { data.query_user_id = Convert.ToInt32(dr["query_user_id"]); }
            catch { }

            try { data.query_time = Convert.ToDateTime(dr["query_time"]); }
            catch { }

            try { data.result_flag = Convert.ToBoolean(dr["result_flag"]); }
            catch { }

            return data;
        }    
        public static unit_logData Construct(DataRow dr)
        {
            unit_logData data = new unit_logData();

            try { data.log_id = Convert.ToInt32(dr["log_id"]); }
            catch { }

            try { data.unit_number = Convert.ToString(dr["unit_number"]); }
            catch { }

            try { data.unit_shelf_number = Convert.ToString(dr["unit_shelf_number"]); }
            catch { }

            try { data.query_user_id = Convert.ToInt32(dr["query_user_id"]); }
            catch { }

            try { data.query_time = Convert.ToDateTime(dr["query_time"]); }
            catch { }

            try { data.result_flag = Convert.ToBoolean(dr["result_flag"]); }
            catch { }

            return data;
        }
        public static Int32 GetPrimaryKey(DataRow dr)
        {
            Int32 PrimaryKey = 0;

            try { PrimaryKey = Convert.ToInt32(dr[unit_logData.PRIMARYKEY_Field]); }
            catch { }
            return PrimaryKey;
        }

    }
}